/***飞机零部件 */
var BaseBodyIE = require('./../BaseBodyIE');
cc.Class(
{
    extends: BaseBodyIE,

    properties:
    {
        prefabBomb:
        {
            default: null,
            type: cc.Prefab,
            displayName: '爆炸特效'
        },

        mainPlane:
        {
            default: null,
            type: cc.Node,
            displayName: '机身主体'
        },

        hpValue:
        {
            default: 2,
            displayName: '血滴数'
        },
        lbHp:
        {
            default: null,
            type: cc.Label,
            displayName: 'lb血'
        },
    },

    onLoad()
    {
        this.refreshLbHp();
    },
    onCollisionEnter: function(other)
    {
        var body = this._super(other);
        if (null == body)
        {
            cc.error('发现不明物品请处理');
            return null;
        }
        return body;
    },

    doCollision(other)
    {
        this._super(other);

        if (this.hpValue >= 2)
        {
            this.hpValue -= 1;
            this.refreshLbHp();
            return;
        }
        this.playBomb(other);
    },

    /**
     * 播放爆炸特效 
     */
    playBomb(other)
    {
        if (null == this.mainPlane)
        {
            cc.error('飞机零部件必须绑定机身');
        }
        else
        {
            if (null != this.prefabBomb)
            {
                var obj = UtilGameObject.createAddparentByPrefabs(this.prefabBomb, this.mainPlane.parent);
                var otherNode = other.node;
                obj.x = otherNode.x;
                obj.y = otherNode.y;

            }
        }
        this.node.destroy();
    },

    refreshLbHp(_hpValue)
    {
        if (null == this.lbHp)
        {
            cc.error('请绑定文本（血）');
            return;
        }

        this.setHpValue(_hpValue);
        this.lbHp.string = this.hpValue;
    },

    setHpValue(_hpValue)
    {
        if (null == _hpValue)
        {
            return;
        }
        this.hpValue = _hpValue;
    }
});
